<template>
	<view>
		<view class="navBar-class">
			<tn-button style="color: black;width: 35px; height: 35px; font-size: 15px;" :border="false"
				@click="handleReturn">
				<text class="tn-icon-left"></text></tn-button>
			<view style="font-size: 15px;margin-right: 42%;">历史记录</view>
		</view>
		<view>
			<view class="history-list">
				<block v-for="(item, index) in goods" :key="index">
					<tn-list-cell :radius="true" :unlined="true"
						style="width: 100px;height: auto;margin-left: 2%;margin-top: 4%;align-items: center;border: 1px dashed black;"
						@click="dian(item.id)">
						<view class="history">
							<view>
								<image :src="item.picUrl" style="border-radius: 5px;width: 100%;height: 90px;"
									mode="scaleToFill" />
							</view>
							<view style="width: 100%;text-align: center;margin-top: 1px;">
								<text style="color: #E24F56;font-size: 8rpx;">￥{{item.counterPrice}}</text><br />
								<text style="">{{item.name}}</text>
							</view>
						</view>
					</tn-list-cell>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				historys: [],
				goods: []
			}
		},
		mounted() {
			this.getHistory()
		},
		methods: {
			dian(id) {
				uni.navigateTo({
					url: "/pages/index/productDetails/productDetails?id=" + id
				})
			},
			handleReturn() {
				uni.navigateBack({
					delta: 1
				});
			},
			getHistory() {
				let user = uni.getStorageSync("userInfo");
				let that = this
				uni.request({
					url: this.baseUrl + "/wx/histories/getHistoryRecords?userId=" + user.id,
					success: function(res) {
						that.historys = res.data.data
						if (that.historys != undefined) {
							let goods = that.historys.map(item => item.goodId)
							that.getGoods(goods)
						}
					},
					fail(e) {
						console.log(e);
					}
					// uni.request({
					// 	url: this.baseUrl + "/wx/histories/getHistoryRecords?userId=" + user.id,
					// 	method: 'GET',
					// 	
				})
			},
			getGoods(goodsId) {
				let that = this;
				uni.request({
					url: this.baseUrl + "/wx/goods/loadProductHistory",
					method: 'POST',
					data: JSON.stringify(goodsId),
					success: function(res) {
						that.goods = res.data.data
					},
					fail(e) {
						console.log(e);
					}
				})
			}
		}
	}
</script>

<style>
	.navBar-class {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 8%;
		height: auto;

	}

	.history-list {
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		width: 98%;
		margin-left: 1%;
	}

	.history {
		display: flex;
		flex-direction: column;
	}
</style>